package com.yh.spring.mybatis.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yh.spring.mybatis.dao.ProductMapper;
import com.yh.spring.mybatis.model.Page;
import com.yh.spring.mybatis.model.Product;

import com.yh.spring.mybatis.service.IProductService;


@Service("productService")
public class ProductServiceImpl implements IProductService {

	
	
	@Autowired
	private ProductMapper productMapper;
	@Override
	public Product getProduct(Product product) {
		// TODO Auto-generated method stub
		return productMapper.getProduct(product);
	}

	@Override
	public void insertProduct(Product product) {
		// TODO Auto-generated method stub
		productMapper.insertProduct(product);
	}

	@Override
	public void deleteProduct(Product product) {
		// TODO Auto-generated method stub
		productMapper.deleteProduct(product);
	}

	@Override
	public void updateProduct(Product product) {
		// TODO Auto-generated method stub
		productMapper.updateProduct(product);
	}

	@Override
	public Page queryLikeProduct(Map<String, Object> cond) {
		// TODO Auto-generated method stub
		Page page=new Page();
		page.setTotalNum(productMapper.getLikeProductCount(cond));
		int pageSize=Integer.parseInt(String.valueOf(cond.get("pageSize")));
		int surrentPage=Integer.parseInt(String.valueOf(cond.get("surrentPage")));
		
		page.setSurrentPage(surrentPage);
		
		page.setTotalPage(page.getTotalNum()/pageSize+(page.getTotalNum()%pageSize==0?0:1));
		
		page.setResult(productMapper.getLikeProduct(cond));
		return page;
	}


}
